import pygame
import math


class Boss(object):
    def __init__(self,time,totaltime):
        super(Boss,self).__init__()
        self.img = pygame.image.load("../media/images/coda.png").convert_alpha()
        self.rect = self.img.get_rect()
        self.rect.centery = 200
        self.rect.centerx = 1300
        self.status = "sad"
        self.happy = False
        self._vConst = 2
        self.xPos=200
        self.inbounds=True
        self.time=time
        self.totaltime=totaltime
        self.blast=False
        self.prep=False
        self.blastHeight=0
        self.health=200
        


    def update(self,time,totaltime):
        velocity=0
        x=0
        if self.xPos >0:
            self.xPos-=2
            x=-2
        else:
            velocity = self._vConst * time 

        if self.inbounds==True:
            if self.rect.centery>400 or self.rect.centery < 100:           
                self._vConst*=-1.0
                self.inbounds=False
        if self.inbounds==False:
            if self.rect.centery<380 and self.rect.centery > 120:
                self.inbounds=True
        
        self.rect.move_ip(x,velocity)

       # print str(totaltime)+" "+str(self.totaltime)
        if self.prep==False and self.blast==False and (totaltime-self.totaltime)>=2000:
            self.totaltime=totaltime
            self.prep=True

        if self.prep and (totaltime-self.totaltime)>=2000:
            self.totaltime=totaltime
            self.blast=True
            self.blastHeight=0
            self.prep=False
        
        
            

    def draw(self,screen):
        screen.blit(self.img,self.rect)
        if self.prep:
            pygame.draw.lines (screen,(0,255,0),False,[(1050,self.rect.centery),(-10,self.rect.centery)],2)
           
        if self.blast:
            if self.blastHeight<100:            
                pygame.draw.lines (screen,(255,0,0),False,[(1050,self.rect.centery),(-10,self.rect.centery)],50-math.fabs(self.blastHeight-50))
                self.blastHeight+=5
            else:
                self.blast=False
                


    def collided(self,bullet_list = []):
        if len(bullet_list) > 0:
            collide_rect = pygame.Rect(self.rect.centerx-20,self.rect.centery-30,40,60)
            for bullet in bullet_list:
                if collide_rect.colliderect(bullet.rect):
                    bullet_list.remove(bullet)
                    del bullet
#                    self.health-=1
                    return True
        else:
            return False
    def take_damage(self,amount):
        self.health -= amount
        if self.health <= 0:
            return "dead"
        else:
            return "not dead"
